<template>
  <div class="common-layout">
    <el-container class="home">
      <main-header></main-header>
      <app-center></app-center>
      <el-container class="main">
        <div class="side-menu" v-if="topMenuList.length > 0">
          <el-menu
            ref="menuRef"
            :router="true"
            :collapse="showSide"
            :default-active="defaultActive"
            class="menu-list"
          >
            <menu-tree
              :leftMenuList="topMenuList"
              :showSide="showSide"
            ></menu-tree>
          </el-menu>
          <img
            src="@/assets/menu/icon-item.png"
            alt=""
            class="expand"
            @click="showSideMenu"
          />
        </div>

        <el-container class="all-right">
          <el-main class="body">
            <!-- {{ keepAliveInclude }} -->
            <RouterView v-slot="{ Component }">
              <KeepAlive :include="keepAliveInclude">
                <component :is="Component"></component>
              </KeepAlive>
            </RouterView>
          </el-main>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { usePermission } from "@/compositions/main/usePermission";
import { useMenu } from "@/compositions/main/useMenu";
import MenuTree from "@/components/menu/menu.vue";


const store = useStore();
const { condition } = usePermission();
const { defaultActive, showSide, showSideMenu } = useMenu();

// 使用include缓存
const keepAliveInclude = computed(() => {
  return store.state.user.keepAliveInclude;
});

const topMenuList = computed(() => {
  if (store.state.user.allPermission) {
    const temp = store.state.user.allPermission.find((i: any) => i.serviceType == store.state.user.currentService);

    if (temp) {
      return temp.permissionLayer
    } else {
      return []
    }
  } else {
    return [];
  }
});

</script>

<style lang="scss" scoped>
.main {
  width: calc(100vw - 60px);
  margin-left: 60px;
}
.all-right {
  height: calc(100vh - 60px);
  overflow-y: auto;
}

.home {
  display: block;
  position: relative;
  padding-top: 60px;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  outline: none;
  min-width: 1158px;

  :deep(.el-main) {
    padding: 0;
  }
}

.body {
  height: 100%;
  overflow: auto;
}

.side-menu {
  height: calc(100vh - 60px);
  flex: none;
  box-shadow: 0px 2px 12px 0px rgba(0, 0, 0, 0.1);
  background: #fff;
  user-select: none;
  overflow-y: auto;
  transition: width 400ms;
  box-sizing: border-box;
  position: relative;
  z-index: 22;

  .expand {
    position: absolute;
    bottom: 20px;
    right: 16px;
    width: 24px;
    height: 24px;
    z-index: 33;
  }

  .menu-list {
    margin-top: 12px;
    height: calc(100% - 12px);
    color: #303133;
    background: #fff;
    border: none;
  }
  :deep(.el-sub-menu) {
    &.is-active {
      .el-sub-menu__title {
        color: #0052d9;
        font-weight: 600;
      }
    }
  }
  :deep(.el-sub-menu__title) {
    height: 40px;
    display: flex;
    align-items: center;
    color: #303133;

    .iconfont {
      width: 18px;
      margin-right: 16px;
    }

    &:hover {
      color: #001e70;
      background: #fff;
    }
  }

  :deep(.el-menu-item) {
    height: 40px;
    display: flex;
    align-items: center;
    font-size: 14px;
    font-weight: 400;
    color: #303133;

    a {
      display: flex;
      align-items: center;
      height: 40px;
      color: #303133;
      span {
        height: 40px;
        line-height: 40px;
      }
    }

    img {
      width: 18px;
      height: 18px;
      margin-right: 16px;
    }

    &:hover {
      color: #0052d9;
      background: #e8f2ff;
      font-weight: 600;

      a {
        color: #0052d9;
        // background: #e8f2ff;
        font-weight: 600;
      }
    }

    &.is-active {
      color: #0052d9;
      background: #e8f2ff;
      font-weight: 600;

      a {
        color: #0052d9;
        // background: #e8f2ff;
        font-weight: 600;
      }
    }
  }

  :deep(.el-menu) {
    width: 180px;
    overflow-x: hidden;
  }

  :deep(.el-menu--collapse) {
    width: 60px;
  }
}
</style>
